package d4_bufferstream;

import java.io.*;

public class timetest {
    public static final String SRC_FILE ="D:\\wuyong\\AA1BAd5P.jfif";

    public static final String DEST_FILE ="D:\\wuyong\\bbb\\";

    public static void copy1() {
        long startime = System.currentTimeMillis();
        try (
                InputStream isr = new FileInputStream(SRC_FILE);
                OutputStream os = new FileOutputStream(DEST_FILE+"1.jfif");
                ){
            int b;
            while ((b=isr.read())!=-1){
                os.write(b);
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        long endtime = System.currentTimeMillis();
        System.out.println("低级时间是："+(endtime - startime));
    }
    public static void copy2() {
        long startime = System.currentTimeMillis();
        try (
                InputStream isr = new FileInputStream(SRC_FILE);

                OutputStream os = new FileOutputStream(DEST_FILE+"2.jfif");

        ){
            byte[] buf = new byte[1024];
            int b;
            while ((b=isr.read(buf))!=-1){
                os.write(buf, 0, b);
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        long endtime = System.currentTimeMillis();
        System.out.println("低级用字节数组时间是："+(endtime - startime));
    }
    public static void copy3() {
        long startime = System.currentTimeMillis();
        try (
                InputStream isr = new FileInputStream(SRC_FILE);
                BufferedInputStream bis = new BufferedInputStream(isr);
                OutputStream os = new FileOutputStream(DEST_FILE+"3.jfif");
                BufferedOutputStream bos = new BufferedOutputStream(os);
        ){
            int b;
            while ((b=bis.read())!=-1){
                bos.write(b);
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        long endtime = System.currentTimeMillis();
        System.out.println("高级时间是："+(endtime - startime));
    }
    public static void copy4() {
        long startime = System.currentTimeMillis();
        try (
                InputStream isr = new FileInputStream(SRC_FILE);
                BufferedInputStream bis = new BufferedInputStream(isr);
                OutputStream os = new FileOutputStream(DEST_FILE+"4.jfif");
                BufferedOutputStream bos = new BufferedOutputStream(os);
        ){
            byte[] buf = new byte[1024];
            int b;
            while ((b=bis.read(buf))!=-1){
                bos.write(buf, 0, b);
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        long endtime = System.currentTimeMillis();
        System.out.println("高级用字节数组时间是："+(endtime - startime));
    }
    public static void main(String[] args) {
        copy1();
        copy2();
        copy3();
        copy4();
    }
}

